-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.c
More file actions
40 lines (30 loc) · 720 Bytes
/
Solution.c
File metadata and controls
40 lines (30 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
void rotateArray(int arr[], int n, int k) {
k = k % n;
int temp[n];
for (int i = 0; i < n; i++) {
temp[(i + k) % n] = arr[i];
}
for (int i = 0; i < n; i++) {
arr[i] = temp[i];
}
}
int main() {
int n, k;
printf("Enter the size of the array: ");
scanf("%d", &n);
int arr[n];
printf("Enter the elements of the array:\n");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
printf("Enter the number of positions to rotate: ");
scanf("%d", &k);
rotateArray(arr, n, k);
printf("Rotated array: ");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}